package com.recruit.g1.interestedJobs.service.impl;

import com.recruit.g1.interestedJobs.mapper.InterestedJobsMapper;
import com.recruit.g1.interestedJobs.service.InterestedJobsService;
import com.recruit.g1.pojo.job.entity.Job;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;

@Slf4j
@Service
public class InterestedJobsImpl implements InterestedJobsService {
    @Autowired
    InterestedJobsMapper interestedJobsMapper;
    @Override
    public List<Job> selectInterestedJobs(Long userId) {
        log.debug("interestedJobsQuery的值为",userId);
        List<Job> list = interestedJobsMapper.selectInterestedJobs(userId);
        /*for(){///////////////////

        }///////////////////////////////*/
        // 遍历每个Job对象，将welfare字符串分割为List
        for (Job job : list) {
            String welfareStr = job.getWelfare();
            if (welfareStr != null && !welfareStr.isEmpty()) {
                // 按逗号分割字符串，并转换为List
                String[] welfareArray = welfareStr.split(",");
                List<String> welfareList = Arrays.asList(welfareArray);
                job.setWelfareList(welfareList); // 设置到Job对象中
            }
        }
        log.debug("list的值为{}",list);
        return list;
    }

    @Override
    public List<Job> selectBmJob(Long userId, Long jobId) {
        log.debug("传过来的userID的值为"+userId+"传过来的jobId的值为"+jobId);
        List<Job> list = interestedJobsMapper.selectBmJob(userId, jobId);
        for (Job job : list) {
            String welfareStr = job.getWelfare();
            if (welfareStr != null && !welfareStr.isEmpty()) {
                // 按逗号分割字符串，并转换为List
                String[] welfareArray = welfareStr.split(",");
                List<String> welfareList = Arrays.asList(welfareArray);
                job.setWelfareList(welfareList); // 设置到Job对象中
            }
        }
        log.debug("list的值为{}",list);
        return list;
    }

    @Override
    public void deleteInterestedJobs(Long jobId) {
        log.debug("传过来的jobId的值为"+jobId);
        interestedJobsMapper.deleteInterestedJobs(jobId);
    }

    @Override
    public List<Job> selectBmJobs(Long userId) {
        log.debug("bmJobsQuery的值为",userId);
        List<Job> list = interestedJobsMapper.selectBmJobs(userId);
        // 遍历每个Job对象，将welfare字符串分割为List
        for (Job job : list) {
            String welfareStr = job.getWelfare();
            if (welfareStr != null && !welfareStr.isEmpty()) {
                // 按逗号分割字符串，并转换为List
                String[] welfareArray = welfareStr.split(",");
                List<String> welfareList = Arrays.asList(welfareArray);
                job.setWelfareList(welfareList); // 设置到Job对象中
            }
        }
        log.debug("list的值为{}",list);
        return list;
    }
}
